home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / INPUT / INPUT_PO.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  5.4 KB  |  168 lines

  1. package sub_arctic.input;
  2.  
  3. import sub_arctic.lib.manager;
  4. import sub_arctic.lib.sub_arctic_error;
  5.  
  6. import java.util.Vector;
  7.  
  8. /**
  9.  * Abstract base class for all input policies.  An input policy is an object
  10.  * which uses a set of agents to deliver an event according to a particular
  11.  * policy (such as the positional policy that delivers events based on their
  12.  * position).  This class provides the basic API along with implementation
  13.  * of an agent list and related manipulation methods.
  14.  *
  15.  * @author Scott Hudson
  16.  */
  17. public abstract class input_policy {
  18.  
  19.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  20.  
  21.   /** Simple constructor */
  22.   public input_policy() 
  23.     { 
  24.       _agent_list = new Vector();
  25.     }
  26.  
  27.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  28.  
  29.   /** The agent list for this policy.  This contains dispatch_agent objects. */
  30.   protected Vector _agent_list;
  31.  
  32.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  33.  
  34.   /** The number of agents in the policies agent list. */
  35.   public int num_agents() {return _agent_list.size();}
  36.  
  37.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  38.  
  39.   /** Return the agent at a given index in the agent list. 
  40.    * @param int indx the index of the agent we want. 
  41.    * @returns dispatch_agent the agent at that position.
  42.    */
  43.   public dispatch_agent agent(int indx) 
  44.     {
  45.       /* bounds check */
  46.       if (indx < 0 || indx >= num_agents())
  47.     throw new sub_arctic_error("Agent index out of bounds");
  48.  
  49.       /* pull out the agent */
  50.       return (dispatch_agent)_agent_list.elementAt(indx);
  51.     }
  52.  
  53.    //had:
  54.    //* @exception index_bounds if the index given is out of range.
  55.  
  56.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  57.  
  58.   /** 
  59.    * Add an agent to the agent list after the one given.  If after is coded
  60.    * as null, then the agent is placed at the end of the agent list.
  61.    *
  62.    * @param dispatch_agent add   the agent to add to the list.
  63.    * @param dispatch_agent after the agent to place it after (or null to 
  64.    *                             indicate that it should go at the end of the 
  65.    *                             list).
  66.    */
  67.   public void add_agent_after(dispatch_agent add, dispatch_agent after)
  68.     {
  69.       /* if we have nothing to go after put it at the end */
  70.       if (after == null)
  71.     _agent_list.addElement(add);
  72.       else
  73.     {
  74.       int indx = _agent_list.indexOf(after);
  75.       if (indx < 0)
  76.         throw new sub_arctic_error(
  77.           "Attempt to install dispatch agent after uninstalled agent");
  78.       else
  79.         /* put it right after the one given */
  80.         _agent_list.insertElementAt(add,indx+1);
  81.     }
  82.     }
  83.  
  84.    //had:
  85.    //* @exception bad_value if the after agent is not in the list.
  86.  
  87.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  88.  
  89.   /** 
  90.    * Add an agent to the agent list before the one given.  If before is coded
  91.    * as null, then the agent is placed at the beginning of the agent list.
  92.    *
  93.    * @param dispatch_agent add   the agent to add to the list.
  94.    * @param dispatch_agent after the agent to place it before (or null to 
  95.    *                             indicate that it should go at the beginning 
  96.    *                             of the list).
  97.    */
  98.   public void add_agent_before(dispatch_agent add, dispatch_agent before) 
  99. {
  100.       /* if we have nothing to go before put it at the beginning */
  101.       if (before == null)
  102.     _agent_list.insertElementAt(add,0);
  103.       else
  104.     {
  105.       int indx = _agent_list.indexOf(before);
  106.       if (indx < 0)
  107.         throw new sub_arctic_error(
  108.           "Attempt to install dispatch agent before uninstalled agent");
  109.       else
  110.         /* put it right before the one given */
  111.         _agent_list.insertElementAt(add,indx);
  112.     }
  113.     }
  114.  
  115.    //had:
  116.    //* @exception bad_value if the before agent is not in the list.
  117.  
  118.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  119.  
  120.   /** 
  121.    * Attempt to dispatch an event under this policy.
  122.    * @param event evt the event to dispatch.
  123.    * @return boolean indicating whether the event was dispatched and consumed.
  124.    */
  125.   public abstract boolean dispatch_event(event evt);
  126.   //
  127.   // typical implementation might look something like:
  128.   //
  129.   //  {
  130.   //    dispatch_agent an_agent;
  131.   //
  132.   //    /* walk down the agent list */
  133.   //    for (int i = 0; i < num_agents(); i++)
  134.   //      {
  135.   //        /* try to dispatch with the agent.  if it takes it, we are done */
  136.   //        an_agent = (dispatch_agent)_agent_list.elementAt(i);
  137.   //        if (an_agent.event_is_useful(evt) && 
  138.   //          an_agent.dispatch_event(evt, ??, ??, manager.event_seq_num()))
  139.   //          return true;
  140.   //      }
  141.   //
  142.   //      /* nobody wanted it */
  143.   //      return false;
  144.   //  }
  145.  
  146.    //had:
  147.    //* @exception general
  148.  
  149.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  150. };
  151.  
  152. /*=========================== COPYRIGHT NOTICE ===========================
  153.  
  154. This file is part of the subArctic user interface toolkit.
  155.  
  156. Copyright (c) 1996 Scott Hudson and Ian Smith
  157. All rights reserved.
  158.  
  159. The subArctic system is freely available for most uses under the terms
  160. and conditions described in 
  161.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  162. and appearing in full in the lib/interactor.java source file.
  163.  
  164. The current release and additional information about this software can be 
  165. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  166.  
  167. ========================================================================*/
  168.